<?php
namespace app\index\controller;

use think\Controller;

class Common extends Controller
{

	public function _initialize()
	{

		// var_dump($_SERVER['HTTP_USER_AGENT']);exit;
		// if(!session('user')){
		// 	$this->redirect(url('index/login/weixinloin'));
  //           // $this->error("还没有登录 ,请先登录",url('index/login/index'));
  //       }


		$rule = strtolower(request()->module()."/".request()->controller()."/".request()->action());

		$auth = [
			'index/user/set',
			'index/user/post',
			'index/user/index',
			'index/jie/add',
			'index/jie/collect',
			'index/jie/reply',
			'index/jie/zan',
			'index/user/sign',
		];

		if(in_array($rule,$auth)){
			if(!session('user')){
				if($this->is_weixin()){
					session('return_url',$rule);
					$this->redirect(url('index/login/weixinloin'));
				}else{
					$this->error("还没有登录 ,请先登录",url('index/login/index'));
				}
	        }
		}
	}

	public function is_weixin(){ 

		if(strpos($_SERVER['HTTP_USER_AGENT'],'MicroMessenger') !== false){
		        return true;
	    }{
			return false;	
	    }
	}
	
}